package graphx

import org.apache.spark.graphx.{Edge, Graph}
import org.apache.spark.{SparkConf, SparkContext}

object connectedComponentsExample extends App{
  val conf = new SparkConf().setAppName("connected-components-scala").setMaster("local[2]")
  val sc = new SparkContext(conf)

  val g =Graph(sc.makeRDD((1L to 7L).map((_,""))),
    sc.makeRDD(Array(Edge(2L,5L,"2-5"),Edge(5L,3L,"5-3"),Edge(3L,2L,"3-2"),Edge(4L,5L,"4-5"),Edge(6L,7L,"6-7"))))

  //需要说明的是connectedComponents 返回的是 二元元组 _1 是顶点  _2是顶点属于的联通组件
  g.connectedComponents.vertices.foreach(data=>println(data._1,data._2))
}
